"""
 Pandas数据分析实战
 第1部分 Pandas 核心基础
 第2章 Series 对象
"""
import numpy as np
import pandas as pd


def create_series():
    print(pd.Series())


def create_series_value():
    ice_cream_flavors = [
        'Chocolate',
        'Vanilla',
        'Strawberry',
        'Rum Raisin'
    ]
    print(pd.Series(data=ice_cream_flavors))


def create_series_value_index():
    ice_cream_flavors = [
        'Chocolate',
        'Vanilla',
        'Strawberry',
        'Rum Raisin'
    ]
    days_of_week = ('Monday', 'Wednesday', 'Friday', 'Saturday')
    print(pd.Series(ice_cream_flavors, days_of_week))
    print(pd.Series(data=ice_cream_flavors, index=days_of_week))


def create_series_type():
    bunch_of_bools = [True, False, False]
    print(pd.Series(bunch_of_bools))

    stock_prices = [985.32, 950.44]
    print(pd.Series(stock_prices))

    lucky_number = [4, 8, 15, 16, 23, 42]
    print(pd.Series(lucky_number))


def create_series_dtype():
    lucky_number = [4, 8, 15, 16, 23, 42]
    print(pd.Series(lucky_number, dtype="float"))


def create_series_nan():
    temperatures = [94, 88, np.nan, 91]
    print(pd.Series(temperatures))


def dic_create_series():
    calorie_info = {
        'Cereal': 125,
        'Choolate Bar': 406,
        'Ice Cream Sundae': 342
    }
    series = pd.Series(calorie_info)
    # print(series.values)
    # print(series.index)
    # print(type(series.values))
    # print(type(series.index))
    print(series.index)
    print(series.dtype)
    print(series.size)
    print(series.shape)
    print(series.is_unique)
    print(series.is_monotonic_decreasing)


def tep_create_series():
    tep = ('Red', 'Green', 'Blue')
    series = pd.Series(tep)
    print(pd.Series(tep))
    print(series.values)
    print(type(series.values))


def tep1_create_series():
    rgb_color = [(120, 41, 26), (196, 165, 45)]
    print(pd.Series(rgb_color))


def set_create_series():
    my_set = {'Ricky', 'Bobby'}
    print(pd.Series(my_set))


def set_create_series1():
    my_set = {'Ricky', 'Bobby'}
    print(pd.Series(list(my_set)))


def create_series_by_numpy():
    random_randint = np.random.randint(0, 101, 10)
    print(random_randint)
    print(pd.Series(random_randint))


def challenge_code():
    superheroes = [
        'Batman',
        'Superman',
        'Spider-Man',
        'Iron Man',
        'Captain America',
        'Wonder Woman']
    strength_levels = (100, 120, 90, 95, 110, 120)
    # print(pd.Series(superheroes))
    # print(pd.Series(strength_levels))
    heroes = pd.Series(data=strength_levels, index=superheroes)
    # print(heroes)
    # print(heroes.head(2))
    # print(heroes.tail(4))
    # print(heroes.nunique())
    print(heroes.mean())
    print(heroes.max())
    print(heroes.min())
    print(heroes * 2)
    print(dict(heroes))


if __name__ == '__main__':
    challenge_code()
    # dic_create_series()
    # tep_create_series()
    # print(pd.Series(data=[1, 3, 6]).is_monotonic_increasing)
    # print(pd.Series(data=[6, 3, 1]).is_monotonic_decreasing)
    # values = range(0, 500, 5)
    # nums = pd.Series(data=values)
    # print(nums)
    # print(nums.head())
    # print(nums.tail())
    # nums.div()
    # numbers = pd.Series([1, 2, 3, np.nan, 4, 5])
    # print(numbers)
    # print(numbers.count())
    # print(numbers.sum())
    # print(numbers.sum(skipna=False))
    # print(numbers.sum(min_count=3))
    # print(numbers.product())
    # print(numbers.product(skipna=False))
    # print(numbers.product(min_count=3))
    # print(numbers.cumsum())
    # print(numbers.cumsum(skipna=False))
    # print(numbers.pct_change())
    #
    # print(numbers.pct_change(fill_method='pad'))
    # print(numbers.pct_change(fill_method='ffill'))
    # print(numbers.pct_change(fill_method='bfill'))
    # print(numbers.pct_change(fill_method='backfill'))
    #
    # print(numbers.ffill().pct_change())
    # print(numbers.bfill().pct_change())
    # print(numbers.backfill().pct_change())
    # print(numbers.mean())
    # print(numbers.median())
    # print(numbers.std())
    # print(numbers.max())
    # print(numbers.min())
    # print(numbers.describe())
    # print(numbers.sample(3))
    # authors = pd.Series(['Hemingway', 'Orwell', 'Dostoevsky', 'Fitzgerald', 'Orwell'])
    # print(authors.unique())
    # print(authors.nunique())
    # s1 = pd.Series(data=[5, np.nan, 15], index=['A', 'B', 'C'])
    # print(s1)
    # print(s1+3)
    # print(s1.add(3))
    # print(s1-5)
    # print(s1.sub(5))
    # print(s1.subtract(5))
    # print(s1 * 2)
    # print(s1.mul(2))
    # print(s1.multiply(2))
    # print(s1 / 2)
    # print(s1.div(2))
    # print(s1.divide(2))
    # print(s1 // 4)
    # print(s1.floordiv(4))
    # print(s1 % 3)
    # cities = pd.Series(
    #     data=['San Francisco', 'Los Angeles', 'Las Veges', np.nan]
    # )
    # print(len(cities))
    # print(type(cities))
    # print(dir(cities))
    # print(list(cities))
    # print(dict(cities))
    # print('Las Vegas' in cities)
    # print(2 in cities)
    # print('Las Veges' in cities.values)
    # print(100 not in cities)
    # print('Paris' not in cities.values)
